package com.aix.demo;

public class Node {

    //数据
    private int value;
    //下一个节点
    private Node next;

    public Node(int value, Node next) {
        this.value = value;
        this.next = next;
    }

    public Node(int value) {
        this.value = value;
    }

    public Node() {
    }

    @Override
    public String toString() {
        String val=Integer.toString(value);
        if (next!=null){
            val=val.concat(" hasNext ");
            val=val.concat(next.toString());
        }
        return  val;
    }

    public void addToTail(Node node){
        Node temp=this;
        while (temp.hasNext()){
            temp=temp.next;
        }

        temp.next=node;
    }

    public void addToHead(Node head, Node node){
        node.next=head.next;
        head.next=node;
    }

    public Node addToNext(Node node){
        node.next=this.next;
        this.next=node;
        return node;
    }

    public boolean hasNext(){
        return this.next ==null ? false : true;
    }

    public Node addNext(Node node){
        this.next=node;

        return node;
    }

    public int getValue(){
        return value;
    }
    public void setValue(int value) {
        this.value = value;
    }

    public Node getNext() {
        return next;
    }

    public Node setNext(Node netx) {
        this.next = netx;
        return this;
    }
}
